package net.csdn.business.mirror.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.csdn.business.mirror.service.MqProjectChangeImplement;
import net.csdn.business.mirror.service.impl.*;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;

public class MirrorMqEnum {

    @Getter
    @AllArgsConstructor
    public enum EventType {
        IMPORT("project.import", MqImportImplement.class),
        MIRROR("project.mirror", MqMirrorImplement.class),
        IMPORT_FAILED("project.import.failed", MqImportFailedImplement.class),
        MIRROR_FAILED("project.mirror.failed", MqMirrorFailedImplement.class),
        PROJECT_DELETE("project.delete", MqProjectDeleteImplement.class),
        ;

        private String type;
        private Class<? extends MqProjectChangeImplement> projectChangeImplementService;

        public static final Map<String, EventType> MAP = Maps.newHashMap();

        static {
            for (EventType eventType : EventType.values()) {
                MAP.put(eventType.type, eventType);
            }
        }

        public static EventType parse(String eventType) {
            if (StringUtils.isBlank(eventType)) {
                return null;
            }
            return MAP.get(eventType);
        }

        public static boolean exists(String eventType) {
            EventType et = parse(eventType);
            return Objects.nonNull(et);
        }
    }
}
